// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License 2.0;
// you may not use this file except in compliance with the Elastic License 2.0.

package license

import (
	"crypto/rsa"
	"crypto/x509"
	"encoding/json"
	"fmt"
	"os"
	"testing"

	"github.com/stretchr/testify/require"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"sigs.k8s.io/controller-runtime/pkg/client"

	commonv1 "github.com/elastic/cloud-on-k8s/v3/pkg/apis/common/v1"
)

var (
	licenseFixtureV3 = EnterpriseLicense{
		License: LicenseSpec{
			UID:                "1A3E10B3-78AD-459B-86B9-230A53B3F282",
			IssueDateInMillis:  1548115200000,
			ExpiryDateInMillis: 1561247999999,
			IssuedTo:           "Ben Bitdiddle",
			Issuer:             "Alyssa P. Hacker,",
			StartDateInMillis:  1548115200000,
			Type:               "enterprise",
			MaxInstances:       23,
			Signature:          string(signatureFixtureV3),
			Version:            3, // purely documentation neither verified nor signed
		},
	}
	licenseFixtureV4 = EnterpriseLicense{
		License: LicenseSpec{
			UID:                "1A3E10B3-78AD-459B-86B9-230A53B3F282",
			IssueDateInMillis:  1548115200000,
			ExpiryDateInMillis: 1561247999999,
			IssuedTo:           "Ben Bitdiddle",
			Issuer:             "Alyssa P. Hacker,",
			StartDateInMillis:  1548115200000,
			Type:               "enterprise",
			MaxResourceUnits:   46,
			Signature:          string(signatureFixtureV4),
			Version:            4, // purely documentation neither verified nor signed
		},
	}
)

var emptyTrialLicenseFixture = EnterpriseLicense{
	License: LicenseSpec{
		Type: LicenseTypeEnterpriseTrial,
	},
}

func externallySignedLicenseFixture() (EnterpriseLicense, error) {
	exptectedBytes, err := os.ReadFile("testdata/externally-generated-lic.json")
	if err != nil {
		return EnterpriseLicense{}, err
	}

	var lic EnterpriseLicense
	err = json.Unmarshal(exptectedBytes, &lic)
	if err != nil {
		return EnterpriseLicense{}, err
	}
	return lic, nil
}

func withSignature(l EnterpriseLicense, sig []byte) EnterpriseLicense {
	l.License.Signature = string(sig)
	return l
}

func asClientObject(l EnterpriseLicense) client.Object {
	bytes, err := json.Marshal(l)
	if err != nil {
		panic(err)
	}

	return &corev1.Secret{
		ObjectMeta: metav1.ObjectMeta{
			Namespace: "test-system",
			Name:      fmt.Sprintf("test-%s-license", string(l.License.Type)),
			Labels: map[string]string{
				commonv1.TypeLabelName: Type,
				LicenseLabelScope:      string(LicenseScopeOperator),
				LicenseLabelType:       string(l.License.Type),
			},
		},
		Data: map[string][]byte{
			FileName: bytes,
		},
	}
}

func asClientObjects(l EnterpriseLicense, sig []byte) []client.Object {
	return []client.Object{
		asClientObject(withSignature(l, sig)),
	}
}

func publicKeyBytesFixture(t *testing.T) []byte {
	t.Helper()
	bytes, err := x509.MarshalPKIXPublicKey(publicKeyFixture(t))
	require.NoError(t, err)
	return bytes
}

func publicKeyFixture(t *testing.T) *rsa.PublicKey {
	t.Helper()
	key, err := x509.ParsePKCS1PrivateKey(privateKeyFixture)
	require.NoError(t, err)
	return &key.PublicKey
}

var privateKeyFixture = []byte{
	0x30, 0x82, 0x04, 0xa5, 0x02, 0x01, 0x00, 0x02,
	0x82, 0x01, 0x01, 0x00, 0xe3, 0x4d, 0xbc, 0x9b,
	0x76, 0x1e, 0x1a, 0xa4, 0x89, 0x28, 0x6e, 0x0f,
	0x7e, 0x10, 0xf2, 0x87, 0x52, 0xbc, 0x64, 0xd2,
	0x94, 0x46, 0x78, 0xf1, 0x5b, 0xd0, 0xda, 0xd3,
	0xdc, 0x56, 0x6e, 0x62, 0x6f, 0xa1, 0x9e, 0x12,
	0x65, 0x35, 0xcf, 0x92, 0x2e, 0xdd, 0xf3, 0xf2,
	0xd9, 0xf9, 0x99, 0x00, 0xa1, 0x11, 0xfd, 0x34,
	0x0b, 0x43, 0xb5, 0xb5, 0xce, 0x5f, 0xf4, 0xce,
	0x51, 0xf9, 0x35, 0x1f, 0xed, 0x94, 0xd4, 0x2c,
	0x92, 0x95, 0x75, 0x50,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xe0, 0xd2, 0x26, 0x2c, 0x15, 0xe0, 0x8c, 0xd3,
	0xc1, 0xb9, 0x20, 0xff, 0xc0, 0xfd, 0xb8, 0xd9,
	0xa1, 0x72, 0x90, 0xd8, 0x25, 0x8b, 0x10, 0x2b,
	0x94,
}

var signatureFixtureV3 = []byte{
	0x41, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
	0x41, 0x41, 0x30, 0x31, 0x38, 0x47, 0x4c, 0x47,
	0x61, 0x52, 0x44, 0x71, 0x55, 0x45, 0x69, 0x2f,
	0x68, 0x70, 0x68, 0x68, 0x41, 0x41, 0x41, 0x42,
	0x61, 0x45, 0x31, 0x4a, 0x53, 0x55, 0x4a, 0x44,
	0x5a, 0x30, 0x74, 0x44, 0x51, 0x56, 0x46, 0x46,
	0x51, 0x54, 0x51, 0x77, 0x4d, 0x6a, 0x68, 0x74,
	0x4d, 0x31, 0x6c, 0x6c, 0x52, 0x33, 0x46, 0x54,
	0x53, 0x6b, 0x74, 0x48, 0x4e, 0x46, 0x42, 0x6d,
	0x61, 0x45, 0x52, 0x35, 0x61, 0x44, 0x46, 0x4c,
	0x4f, 0x46, 0x70, 0x4f, 0x53, 0x31, 0x56, 0x53,
	0x62, 0x6d, 0x70, 0x34, 0x56, 0x7a, 0x6c, 0x45,
	0x59, 0x54, 0x41, 0x35, 0x65, 0x46, 0x64, 0x69,
	0x62, 0x55, 0x70, 0x32, 0x62, 0x31, 0x6f, 0x30,
	0x55, 0x31, 0x70, 0x55, 0x57, 0x46, 0x42, 0x72,
	0x61, 0x54, 0x64, 0x6b, 0x4f, 0x43, 0x39, 0x4d,
	0x57, 0x69, 0x74, 0x61, 0x61, 0x30, 0x46, 0x76,
	0x55, 0x6b, 0x67, 0x35, 0x54, 0x6b, 0x46, 0x30,
	0x52, 0x48, 0x52, 0x69, 0x57, 0x45, 0x39, 0x59,
	0x4c, 0x31, 0x52, 0x50, 0x56, 0x57, 0x5a, 0x72,
	0x4d, 0x55, 0x67, 0x72, 0x4d, 0x6c, 0x55, 0x78,
	0x51, 0x33, 0x6c, 0x54, 0x62, 0x46, 0x68, 0x57,
	0x55, 0x57, 0x6c, 0x44, 0x4b, 0x30, 0x70, 0x52,
	0x57, 0x47, 0x74, 0x59, 0x4d, 0x55, 0x70, 0x72,
	0x4e, 0x46, 0x64, 0x71, 0x4e, 0x6e, 0x4a, 0x76,
	0x62, 0x31, 0x46, 0x7a, 0x53, 0x33, 0x68, 0x50,
	0x56, 0x57, 0x68, 0x6d, 0x4f, 0x48, 0x52, 0x4f,
	0x5a, 0x47, 0x56, 0x50, 0x59, 0x6d, 0x68, 0x6d,
	0x4d, 0x46, 0x70, 0x47, 0x4d, 0x6c, 0x52, 0x70,
	0x4e, 0x58, 0x42, 0x46, 0x52, 0x6a, 0x52, 0x47,
	0x53, 0x54, 0x5a, 0x55, 0x61, 0x6c, 0x6c, 0x58,
	0x56, 0x31, 0x42, 0x61, 0x59, 0x54, 0x59, 0x72,
	0x64, 0x47, 0x59, 0x33, 0x53, 0x6e, 0x68, 0x54,
	0x4f, 0x56, 0x52, 0x71, 0x59, 0x58, 0x56, 0x6b,
	0x4e, 0x31, 0x4a, 0x4b, 0x4d, 0x45, 0x74, 0x48,
	0x55, 0x6a, 0x5a, 0x72, 0x52, 0x55, 0x46, 0x7a,
	0x63, 0x6d, 0x70, 0x58, 0x62, 0x56, 0x6c, 0x77,
	0x52, 0x55, 0x52, 0x70, 0x63, 0x56, 0x4d, 0x31,
	0x4e, 0x46, 0x52, 0x76, 0x61, 0x6d, 0x6c, 0x6f,
	0x55, 0x30, 0x77, 0x30, 0x5a, 0x55, 0x31, 0x33,
	0x4d, 0x32, 0x49, 0x30, 0x4e, 0x46, 0x55, 0x33,
	0x64, 0x47, 0x6c, 0x4c, 0x57, 0x57, 0x56, 0x48,
	0x59, 0x58, 0x4a, 0x44, 0x4d, 0x6b, 0x52, 0x74,
	0x62, 0x56, 0x64, 0x58, 0x62, 0x6b, 0x74, 0x59,
	0x57, 0x6d, 0x4d, 0x7a, 0x51, 0x57, 0x31, 0x77,
	0x4e, 0x46, 0x70, 0x58, 0x54, 0x48, 0x52, 0x68,
	0x61, 0x53, 0x39, 0x35, 0x5a, 0x7a, 0x52, 0x4e,
	0x62, 0x32, 0x30, 0x32, 0x52, 0x7a, 0x52, 0x5a,
	0x55, 0x43, 0x74, 0x32, 0x4e, 0x46, 0x42, 0x77,
	0x4c, 0x32, 0x4a, 0x49, 0x61, 0x57, 0x64, 0x33,
	0x56, 0x57, 0x70, 0x4e, 0x65, 0x47, 0x64, 0x70,
	0x56, 0x55, 0x5a, 0x75, 0x55, 0x48, 0x4e, 0x49,
	0x64, 0x6d, 0x35, 0x44, 0x62, 0x45, 0x4e, 0x77,
	0x4b, 0x30, 0x5a, 0x53, 0x4f, 0x57, 0x68, 0x6c,
	0x65, 0x46, 0x56, 0x6b, 0x51, 0x6a, 0x49, 0x72,
	0x56, 0x47, 0x77, 0x34, 0x55, 0x48, 0x4a, 0x42,
	0x62, 0x7a, 0x52, 0x72, 0x56, 0x55, 0x6f, 0x33,
	0x4d, 0x45, 0x38, 0x79, 0x62, 0x44, 0x5a, 0x50,
	0x65, 0x47, 0x31, 0x31, 0x4e, 0x46, 0x70, 0x48,
	0x53, 0x6c, 0x59, 0x31, 0x51, 0x57, 0x5a, 0x73,
	0x64, 0x30, 0x35, 0x6c, 0x4d, 0x43, 0x39, 0x73,
	0x4d, 0x31, 0x63, 0x7a, 0x62, 0x30, 0x70, 0x30,
	0x53, 0x45, 0x46, 0x4b, 0x4e, 0x32, 0x46, 0x73,
	0x55, 0x55, 0x6c, 0x45, 0x51, 0x56, 0x46, 0x42,
	0x51, 0x67, 0x41, 0x41, 0x41, 0x51, 0x41, 0x38,
	0x43, 0x41, 0x6d, 0x74, 0x33, 0x65, 0x4e, 0x50,
	0x55, 0x36, 0x50, 0x5a, 0x48, 0x74, 0x71, 0x79,
	0x4e, 0x69, 0x4c, 0x55, 0x44, 0x4e, 0x43, 0x68,
	0x47, 0x41, 0x6a, 0x41, 0x49, 0x5a, 0x67, 0x71,
	0x30, 0x7a, 0x56, 0x74, 0x30, 0x6b, 0x45, 0x72,
	0x68, 0x66, 0x56, 0x45, 0x68, 0x53, 0x6c, 0x5a,
	0x43, 0x7a, 0x4c, 0x52, 0x48, 0x30, 0x67, 0x72,
	0x4f, 0x62, 0x48, 0x43, 0x67, 0x69, 0x53, 0x6f,
	0x53, 0x47, 0x36, 0x35, 0x4d, 0x34, 0x5a, 0x49,
	0x5a, 0x4a, 0x5a, 0x7a, 0x6e, 0x59, 0x5a, 0x34,
	0x6c, 0x53, 0x44, 0x6a, 0x46, 0x7a, 0x4a, 0x32,
	0x58, 0x38, 0x74, 0x53, 0x5a, 0x72, 0x51, 0x4b,
	0x6a, 0x48, 0x31, 0x50, 0x31, 0x79, 0x50, 0x2b,
	0x56, 0x30, 0x44, 0x4c, 0x77, 0x64, 0x73, 0x58,
	0x6d, 0x2b, 0x34, 0x66, 0x6b, 0x6b, 0x38, 0x34,
	0x62, 0x67, 0x72, 0x55, 0x70, 0x52, 0x76, 0x69,
	0x53, 0x38, 0x6f, 0x5a, 0x45, 0x63, 0x63, 0x70,
	0x58, 0x64, 0x72, 0x4e, 0x6e, 0x37, 0x6d, 0x6b,
	0x74, 0x36, 0x68, 0x54, 0x74, 0x34, 0x64, 0x6b,
	0x67, 0x5a, 0x72, 0x6e, 0x6d, 0x31, 0x43, 0x52,
	0x67, 0x55, 0x59, 0x68, 0x55, 0x73, 0x65, 0x7a,
	0x4b, 0x55, 0x72, 0x6d, 0x4e, 0x38, 0x6a, 0x55,
	0x75, 0x43, 0x68, 0x4b, 0x39, 0x2f, 0x65, 0x6f,
	0x71, 0x47, 0x79, 0x31, 0x50, 0x6e, 0x43, 0x4b,
	0x6f, 0x75, 0x4f, 0x74, 0x4f, 0x77, 0x46, 0x5a,
	0x79, 0x68, 0x62, 0x70, 0x2b, 0x55, 0x72, 0x58,
	0x38, 0x6e, 0x49, 0x7a, 0x78, 0x70, 0x2f, 0x4e,
	0x76, 0x75, 0x75, 0x4f, 0x41, 0x43, 0x69, 0x64,
	0x7a, 0x43, 0x6b, 0x56, 0x4e, 0x4b, 0x46, 0x79,
	0x4a, 0x46, 0x50, 0x37, 0x31, 0x70, 0x6f, 0x73,
	0x51, 0x56, 0x30, 0x72, 0x41, 0x50, 0x49, 0x69,
	0x67, 0x67, 0x58, 0x42, 0x30, 0x56, 0x39, 0x4b,
	0x58, 0x45, 0x66, 0x4f, 0x34, 0x74, 0x62, 0x7a,
	0x75, 0x7a, 0x4e, 0x67, 0x4b, 0x63, 0x50, 0x35,
	0x73, 0x37, 0x30, 0x79, 0x43, 0x7a, 0x77, 0x35,
	0x6d, 0x30, 0x2b, 0x6d, 0x58, 0x55, 0x59, 0x75,
	0x72, 0x61, 0x73, 0x79, 0x58, 0x56, 0x54, 0x52,
	0x4b, 0x47, 0x73, 0x6c, 0x33, 0x52, 0x6d, 0x55,
	0x4c, 0x43, 0x6d, 0x6d, 0x4a, 0x6f, 0x53, 0x73,
	0x32, 0x49, 0x32, 0x55, 0x64, 0x2b, 0x35, 0x71,
	0x67, 0x52, 0x4c, 0x47, 0x74, 0x64, 0x4b, 0x2f,
	0x4c, 0x6f, 0x55, 0x4d, 0x69, 0x64, 0x67, 0x6c,
	0x49, 0x79, 0x58, 0x61,
}

var signatureFixtureV4 = []byte{
	0x41, 0x41, 0x41, 0x41, 0x41, 0x77, 0x41, 0x41,
	0x41, 0x41, 0x31, 0x33, 0x67, 0x61, 0x61, 0x32,
	0x76, 0x46, 0x46, 0x71, 0x67, 0x32, 0x50, 0x37,
	0x45, 0x72, 0x74, 0x72, 0x41, 0x41, 0x41, 0x42,
	0x61, 0x45, 0x31, 0x4a, 0x53, 0x55, 0x4a, 0x44,
	0x5a, 0x30, 0x74, 0x44, 0x51, 0x56, 0x46, 0x46,
	0x51, 0x54, 0x51, 0x77, 0x4d, 0x6a, 0x68, 0x74,
	0x4d, 0x31, 0x6c, 0x6c, 0x52, 0x33, 0x46, 0x54,
	0x53, 0x6b, 0x74, 0x48, 0x4e, 0x46, 0x42, 0x6d,
	0x61, 0x45, 0x52, 0x35, 0x61, 0x44, 0x46, 0x4c,
	0x4f, 0x46, 0x70, 0x4f, 0x53, 0x31, 0x56, 0x53,
	0x62, 0x6d, 0x70, 0x34, 0x56, 0x7a, 0x6c, 0x45,
	0x59, 0x54, 0x41, 0x35, 0x65, 0x46, 0x64, 0x69,
	0x62, 0x55, 0x70, 0x32, 0x62, 0x31, 0x6f, 0x30,
	0x55, 0x31, 0x70, 0x55, 0x57, 0x46, 0x42, 0x72,
	0x61, 0x54, 0x64, 0x6b, 0x4f, 0x43, 0x39, 0x4d,
	0x57, 0x69, 0x74, 0x61, 0x61, 0x30, 0x46, 0x76,
	0x55, 0x6b, 0x67, 0x35, 0x54, 0x6b, 0x46, 0x30,
	0x52, 0x48, 0x52, 0x69, 0x57, 0x45, 0x39, 0x59,
	0x4c, 0x31, 0x52, 0x50, 0x56, 0x57, 0x5a, 0x72,
	0x4d, 0x55, 0x67, 0x72, 0x4d, 0x6c, 0x55, 0x78,
	0x51, 0x33, 0x6c, 0x54, 0x62, 0x46, 0x68, 0x57,
	0x55, 0x57, 0x6c, 0x44, 0x4b, 0x30, 0x70, 0x52,
	0x57, 0x47, 0x74, 0x59, 0x4d, 0x55, 0x70, 0x72,
	0x4e, 0x46, 0x64, 0x71, 0x4e, 0x6e, 0x4a, 0x76,
	0x62, 0x31, 0x46, 0x7a, 0x53, 0x33, 0x68, 0x50,
	0x56, 0x57, 0x68, 0x6d, 0x4f, 0x48, 0x52, 0x4f,
	0x5a, 0x47, 0x56, 0x50, 0x59, 0x6d, 0x68, 0x6d,
	0x4d, 0x46, 0x70, 0x47, 0x4d, 0x6c, 0x52, 0x70,
	0x4e, 0x58, 0x42, 0x46, 0x52, 0x6a, 0x52, 0x47,
	0x53, 0x54, 0x5a, 0x55, 0x61, 0x6c, 0x6c, 0x58,
	0x56, 0x31, 0x42, 0x61, 0x59, 0x54, 0x59, 0x72,
	0x64, 0x47, 0x59, 0x33, 0x53, 0x6e, 0x68, 0x54,
	0x4f, 0x56, 0x52, 0x71, 0x59, 0x58, 0x56, 0x6b,
	0x4e, 0x31, 0x4a, 0x4b, 0x4d, 0x45, 0x74, 0x48,
	0x55, 0x6a, 0x5a, 0x72, 0x52, 0x55, 0x46, 0x7a,
	0x63, 0x6d, 0x70, 0x58, 0x62, 0x56, 0x6c, 0x77,
	0x52, 0x55, 0x52, 0x70, 0x63, 0x56, 0x4d, 0x31,
	0x4e, 0x46, 0x52, 0x76, 0x61, 0x6d, 0x6c, 0x6f,
	0x55, 0x30, 0x77, 0x30, 0x5a, 0x55, 0x31, 0x33,
	0x4d, 0x32, 0x49, 0x30, 0x4e, 0x46, 0x55, 0x33,
	0x64, 0x47, 0x6c, 0x4c, 0x57, 0x57, 0x56, 0x48,
	0x59, 0x58, 0x4a, 0x44, 0x4d, 0x6b, 0x52, 0x74,
	0x62, 0x56, 0x64, 0x58, 0x62, 0x6b, 0x74, 0x59,
	0x57, 0x6d, 0x4d, 0x7a, 0x51, 0x57, 0x31, 0x77,
	0x4e, 0x46, 0x70, 0x58, 0x54, 0x48, 0x52, 0x68,
	0x61, 0x53, 0x39, 0x35, 0x5a, 0x7a, 0x52, 0x4e,
	0x62, 0x32, 0x30, 0x32, 0x52, 0x7a, 0x52, 0x5a,
	0x55, 0x43, 0x74, 0x32, 0x4e, 0x46, 0x42, 0x77,
	0x4c, 0x32, 0x4a, 0x49, 0x61, 0x57, 0x64, 0x33,
	0x56, 0x57, 0x70, 0x4e, 0x65, 0x47, 0x64, 0x70,
	0x56, 0x55, 0x5a, 0x75, 0x55, 0x48, 0x4e, 0x49,
	0x64, 0x6d, 0x35, 0x44, 0x62, 0x45, 0x4e, 0x77,
	0x4b, 0x30, 0x5a, 0x53, 0x4f, 0x57, 0x68, 0x6c,
	0x65, 0x46, 0x56, 0x6b, 0x51, 0x6a, 0x49, 0x72,
	0x56, 0x47, 0x77, 0x34, 0x55, 0x48, 0x4a, 0x42,
	0x62, 0x7a, 0x52, 0x72, 0x56, 0x55, 0x6f, 0x33,
	0x4d, 0x45, 0x38, 0x79, 0x62, 0x44, 0x5a, 0x50,
	0x65, 0x47, 0x31, 0x31, 0x4e, 0x46, 0x70, 0x48,
	0x53, 0x6c, 0x59, 0x31, 0x51, 0x57, 0x5a, 0x73,
	0x64, 0x30, 0x35, 0x6c, 0x4d, 0x43, 0x39, 0x73,
	0x4d, 0x31, 0x63, 0x7a, 0x62, 0x30, 0x70, 0x30,
	0x53, 0x45, 0x46, 0x4b, 0x4e, 0x32, 0x46, 0x73,
	0x55, 0x55, 0x6c, 0x45, 0x51, 0x56, 0x46, 0x42,
	0x51, 0x67, 0x41, 0x41, 0x41, 0x51, 0x42, 0x32,
	0x4b, 0x33, 0x52, 0x66, 0x35, 0x51, 0x64, 0x36,
	0x6a, 0x47, 0x46, 0x4e, 0x4e, 0x36, 0x59, 0x63,
	0x33, 0x5a, 0x38, 0x2b, 0x50, 0x2b, 0x2b, 0x73,
	0x48, 0x35, 0x34, 0x57, 0x46, 0x50, 0x6b, 0x59,
	0x46, 0x4c, 0x62, 0x62, 0x57, 0x73, 0x66, 0x4b,
	0x53, 0x4f, 0x6b, 0x45, 0x48, 0x7a, 0x70, 0x36,
	0x6b, 0x49, 0x56, 0x5a, 0x44, 0x36, 0x77, 0x33,
	0x36, 0x73, 0x47, 0x45, 0x31, 0x71, 0x65, 0x45,
	0x6d, 0x68, 0x68, 0x65, 0x66, 0x75, 0x78, 0x57,
	0x75, 0x70, 0x39, 0x70, 0x69, 0x63, 0x48, 0x31,
	0x42, 0x37, 0x35, 0x34, 0x72, 0x66, 0x5a, 0x68,
	0x56, 0x76, 0x51, 0x54, 0x6f, 0x58, 0x39, 0x2b,
	0x39, 0x4d, 0x68, 0x79, 0x74, 0x6e, 0x4d, 0x52,
	0x67, 0x48, 0x46, 0x54, 0x37, 0x61, 0x74, 0x46,
	0x41, 0x4e, 0x2f, 0x78, 0x6a, 0x4e, 0x31, 0x74,
	0x62, 0x76, 0x54, 0x4a, 0x76, 0x38, 0x54, 0x53,
	0x67, 0x48, 0x2b, 0x6a, 0x46, 0x72, 0x70, 0x4e,
	0x65, 0x46, 0x69, 0x32, 0x69, 0x4a, 0x66, 0x48,
	0x72, 0x31, 0x69, 0x79, 0x2b, 0x7a, 0x57, 0x4b,
	0x72, 0x78, 0x49, 0x58, 0x68, 0x45, 0x79, 0x72,
	0x6c, 0x49, 0x51, 0x48, 0x77, 0x38, 0x64, 0x4c,
	0x66, 0x6f, 0x4f, 0x32, 0x63, 0x54, 0x6c, 0x6f,
	0x57, 0x69, 0x75, 0x6d, 0x4c, 0x47, 0x59, 0x4d,
	0x32, 0x65, 0x4d, 0x58, 0x31, 0x79, 0x79, 0x66,
	0x6f, 0x56, 0x69, 0x75, 0x39, 0x64, 0x32, 0x49,
	0x34, 0x52, 0x63, 0x6a, 0x52, 0x6d, 0x4f, 0x73,
	0x7a, 0x70, 0x73, 0x61, 0x69, 0x66, 0x76, 0x38,
	0x37, 0x33, 0x51, 0x6f, 0x4f, 0x34, 0x4a, 0x70,
	0x71, 0x76, 0x51, 0x77, 0x36, 0x69, 0x78, 0x63,
	0x36, 0x2b, 0x6f, 0x34, 0x51, 0x58, 0x70, 0x55,
	0x61, 0x4e, 0x59, 0x70, 0x50, 0x6e, 0x32, 0x77,
	0x72, 0x77, 0x5a, 0x6c, 0x65, 0x34, 0x2f, 0x43,
	0x75, 0x42, 0x36, 0x41, 0x30, 0x6a, 0x78, 0x65,
	0x72, 0x48, 0x4d, 0x57, 0x4c, 0x6b, 0x46, 0x7a,
	0x75, 0x39, 0x68, 0x6d, 0x73, 0x79, 0x65, 0x58,
	0x38, 0x58, 0x62, 0x68, 0x49, 0x33, 0x79, 0x73,
	0x30, 0x35, 0x57, 0x64, 0x4c, 0x69, 0x4f, 0x51,
	0x47, 0x74, 0x54, 0x5a, 0x54, 0x61, 0x7a, 0x78,
	0x67, 0x71, 0x4d, 0x44, 0x6c, 0x45, 0x71, 0x31,
	0x33, 0x7a, 0x4e, 0x63, 0x77, 0x64, 0x61, 0x4a,
	0x43, 0x50, 0x43, 0x66, 0x71, 0x61, 0x71, 0x6a,
	0x53, 0x51, 0x61, 0x69, 0x43, 0x63, 0x77, 0x4f,
	0x7a, 0x65, 0x76, 0x67,
}
